'use strict';

/* Controllers */
  // signin controller
app.controller('SigninFormController', ['$scope', '$http', '$state','InfoUserService','$cookieStore', function($scope, $http, $state,InfoUserService,$cookieStore) {
    $scope.user = {};
    $scope.authError = null;
  /*  $scope.login = function() {
      $scope.authError = null;
      // Try to login
      $http.post('api/login', {email: $scope.user.email, password: $scope.user.password})
      .then(function(response) {
        if ( !response.data.user ) {
          $scope.authError = 'Email or Password not right';
        }else{
          $state.go('app.dashboard-v1');
        }
      }, function(x) {
        $scope.authError = 'Server Error';
      });
    };*/
   
  $scope.login = function(){
  	console.log("test");
   	InfoUserService.login($scope.user).then(function(data){
   		console.log("$cookieStore:",$cookieStore);
			if (data.code=='1001') {
				$state.go('app.userMgr.user');
				$cookieStore.put("sessionId",data.data.sessionId);
				console.log("sessionId:",$cookieStore.get("sessionId"));
			} else if(data.code == '10010011'){
				$scope.authError = data.msg;
			};
		});
  }
}]);